<?php
include_once("../modules/checkA.php");
include_once("../../config.php");
$plate=select_one_line_all_items($table_Prefix."plate","mid = 'member'");
?>


<?
//用来判断当前系统属于什么板块
$system_part = $plate['mid'];

if(!$_REQUEST ['applydate'])
{
    $_REQUEST ['applydate']=date("Y-m");
}
$applydate  = addslashes($_REQUEST ['applydate']);

//include_once("collect-function.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
    <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'modules/head.php'; ?>



    <style>
        body>.detail-staitics-info .agent-list li{font-size: 12px!important; width:100px;}
        body>.detail-staitics-info .layui-table td, .layui-table th{font-size: 12px!important;}
    </style>



    <script language="javascript">
        function printdiv(printpage)
        {
            var newstr = printpage.innerHTML;
            var oldstr = document.body.innerHTML;
            document.body.innerHTML =newstr;
            window.print();
            document.body.innerHTML=oldstr;
            return false;
        }



        function print_btn()
        {
            var bt=document.getElementById("bt");
            var div_print=document.getElementById("div_print");

            printdiv(div_print);

        }

    </script>





</head>

<body>

<div id="topbar"><?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>




        <div id="content">
            <h1>招生汇总</h1>

            <input name="print" type="button" id="bt" value="点击打印" class="layui-btn" onclick="print_btn()"/>

            <a type="button" href="export-member-list-by-department-month.php?applydate=<? echo $applydate ?>" class="layui-btn"> 导出 </a>






            <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
            <div class="list-box">

                <div class="statistic">


                    <div class="term-select-function">
                        <label class="layui-form-label">筛选：</label>
                        <div class="layui-input-block">

<?
                            $oldest_men=select_one_line_all_items($table_Prefix."member","nid > 0 and applydate !='' and applydate is not null order by applydate asc");



date_default_timezone_set('Asia/Shanghai');
$first_day_of_month = date('Y-m',time()) . '-01 00:00:01';
$t = strtotime($first_day_of_month);

$oldest_month=substr($oldest_men['applydate'],0,7);

$endmark=10000;



                            for ($i = 0; $i < $endmark; $i++) {



                                if(date("Y-m",strtotime("-$i month",$t))==$oldest_month)
                                {

                                    $endmark=0;
                                    $showdate[$i]=date("Y-m",strtotime("-$i month",$t));
                                }
                                else
                                {

                                     $showdate[$i]=date("Y-m",strtotime("-$i month",$t));
                                }


                            }


                            ?>


                            <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">

                                <?php
                                for ($i = 0; $i < count($showdate); $i++) {
                                    echo $showdate[$i];
                                    ?>
                                    <option value="collect.php?applydate=<? echo $showdate[$i] ?>&nav-itemed=<? echo $system_part ?>"> <? echo $showdate[$i];?> </option>
                                    <?;}?>
                            </select>

                        </div>
                    </div>


                </div>


         <br class="clearfloat"/>



                <div id="div_print">


<div class="detail-staitics-info"  >


    <?

    $summember=count_by_item($table_Prefix."member", "(sid is null or sid = '0') and applydate like '%".$applydate."%'","");

    $sumcost=sum_total($table_Prefix."member","cost","(sid is null or sid = '0') and applydate like '%".$applydate."%'","");



    $full_detail=select_lines_all_items($table_Prefix."member","","(sid is null or sid = '0')  and applydate like '%".$applydate."%'","");



    //获取所有驾照的类型，并且按照顺序重新排列。
    $license_list=two_d_array_item_in_one_d_array($full_detail,"license");
    asort($license_list);//按照驾照排列，所以asort驾照
    $number_range=array_count_values($license_list);
    $number_range_key=array_keys($number_range);



    //获取所有介绍人，并且按照顺序重新排列。
    $employee_list=two_d_array_item_in_one_d_array($full_detail,"agentid");
    $employee_number_range=array_count_values($employee_list);
    asort($employee_number_range);//按照招生的人数排列，所以asort range
    $employee_number_range_key=array_keys($employee_number_range);




    ?>




<ul>

<li><label>合计招生:</label><? echo $summember?><b> 人</b></li>

<li><label>合收金额:</label><? echo $sumcost?><b> 元</b></li>



</ul>


<h2>驾照类型</h2>
    <ul>
        <?for($i=0;$i<count($number_range);$i++){?>
        <li><label><?echo $number_range_key[$i]?> : </label><?echo $number_range[$number_range_key[$i]] ?><b> 人</b></li>
        <?;}?>
    </ul>

<hr/>



    <?

    if(in_array("admin",$quanxian)){?>
<h2>介绍人统计</h2>
    <ul class="agent-list">
        <?for($i=0;$i<count($employee_number_range);$i++){?>
            <? $agernt=select_one_line_all_items($table_Prefix."employee","nid = '".$employee_number_range_key[$i]."'")?>

            <li><label><?echo $agernt['name']?> : </label><?echo $employee_number_range[$employee_number_range_key[$i]] ?><b> 人</b></b></li>
            <?;}?>
    </ul>

<hr/>
        <?;}?>




<div class="list-boxes layui-form">









                        <?
                        $department_list=select_lines_all_items($table_Prefix."department","","tag = '是'","");
                        ?>


                                    <?

                                    for($i=0;$i<count($department_list);$i++)
                                    {



                                        unset($detail);unset($sum_cost);
$detail=select_lines_all_items($table_Prefix."member","","(sid is null or sid = '0') and departmentid = '".$department_list[$i]['nid']."' and applydate like '%".$applydate."%'","");




                                        echo "<h2>".$department_list[$i]['name']."</h2>";

                                        ?>



                                        <table class="layui-table">
                                            <colgroup>
                                                <col width="60">
                                                <col width="100">
                                                <col >
                                                <col width="120">
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col >
                                                <col width="550">

                                            </colgroup>
                                            <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>姓名</th>
                                                <th>编号</th>
                                                <th>报名日期</th>
                                                <th>驾照</th>
                                                <th>金额</th>
                                                <th>付款状态</th>
                                                <th>付款方式</th>
                                                <th>网点</th>
                                            </tr>
                                            </thead>
                                            <tbody>





                                        <?php
                                        for ($ii = 0; $ii < count($detail); $ii++) {
                                            ?>

                                            <tr <?if($applymodify['nid']){echo "style='color:red'";$status="审核中";}else{$status="正常";}?>>
                                                <td><?echo $ii+1 ?></td>
                                                <td><?echo $detail[$ii]['name']?></td>
                                                <td><?echo $detail[$ii]['mid']?></td>
                                                <td><?echo substr($detail[$ii]['applydate'],0,10)?></td>
                                                <td><?echo $detail[$ii]['license']?></td>
                                                <td><?echo $detail[$ii]['cost']?> </td>
                                                <td><?echo $detail[$ii]['status']?> </td>
                                                <td><?echo $detail[$ii]['payment']?> </td>


                                                <?$department=select_one_line_all_items($table_Prefix."department","nid = '".$detail[$ii]['departmentid']."'");?>
                                                <?$agent=select_one_line_all_items($table_Prefix."employee","nid = '".$detail[$ii]['agentid']."'");?>
                                                <?$coach=select_one_line_all_items($table_Prefix."employee","nid = '".$detail[$ii]['coachid']."'");?>
                                                <td><?echo $department['name'] ?></td>

                                            </tr>



<? $sum_cost[$ii]=$detail[$ii]['cost']?>

                                            <?php
                                        ;}
                                        ?>

                                        <tr>
                                            <td> </td>
                                            <td> </td>
                                            <td> </td>
                                            <td> </td>
                                            <td> </td>
                                            <td>总金额：<? echo array_sum($sum_cost)?></td>
                                            <td> </td>
                                            <td> </td>
                                            <td>报名人数：<?echo count($detail)?></td>
                                        </tr>

                        </tbody>
                    </table>

                         <?
                         ;}
                         ?>

























</div>
</div>


                <!--list-box end-->
            </div>

            <!--content端點01-->
        </div>
        <!--maincontent端點01-->
        <br class="clearfloat"/>
    </div>
    <!--container端點01-->
</div>









<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
